package com.tim.app.ui.activity.selected;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;

import com.application.library.widget.smarttab.SmartTabLayout;
import com.lzy.okhttputils.OkHttpUtils;
import com.tim.app.R;
import com.tim.app.constant.AppKey;
import com.tim.app.server.entry.Problem;
import com.tim.app.ui.activity.BaseActivity;
import com.tim.app.ui.adapter.TabAdapter;
import com.tim.app.ui.fragment.selceted.InviteToAnswerFragment;

/**
 * 邀请回答
 */
public class InviteToAnswerActivity extends BaseActivity {

    private static final String TAG = "InviteToAnswerActivity";

    private SmartTabLayout tab_layout;
    private ViewPager vpInviteToAnswer;
    private TabAdapter pagerAdapter;
    private ImageButton ibBack;

    private String problemId;//问题ID

    InviteToAnswerFragment inviteFriendToAnswerFragment;//邀请还有回答
    InviteToAnswerFragment inviteRecommandToAnswerFragment;//邀请推荐回答

    public static void start(Context context, String problemId) {
        Intent intent = new Intent(context, InviteToAnswerActivity.class);
        intent.putExtra(AppKey.PROBLEM_ID, problemId);
        context.startActivity(intent);
    }

    @Override
    protected void onBeforeSetContentLayout() {
        super.onBeforeSetContentLayout();
    }

    @Override
    protected int getLayoutId() {

        return R.layout.activity_invite_to_answer;
    }

    @Override
    public void initView() {
        tab_layout = (SmartTabLayout) findViewById(R.id.tab_layout);
        vpInviteToAnswer = (ViewPager) findViewById(R.id.vpInviteToAnswer);

        ibBack = (ImageButton) findViewById(R.id.ibBack);
        ibBack.setOnClickListener(this);

        problemId = getIntent().getStringExtra(AppKey.PROBLEM_ID);

        pagerAdapter = new TabAdapter(getSupportFragmentManager());
        inviteFriendToAnswerFragment = new InviteToAnswerFragment();
        inviteRecommandToAnswerFragment = new InviteToAnswerFragment();

        Bundle bundle = new Bundle();
        bundle.putString("problemId",problemId);
        bundle.putInt("type",AppKey.INVITE_TYPE_FRIEND);
        inviteFriendToAnswerFragment.setArguments(bundle);

        Bundle bundle1 = new Bundle();
        bundle1.putString("problemId",problemId);
        bundle1.putInt("type",AppKey.INVITE_TYPE_RECOMMAND);
        inviteRecommandToAnswerFragment.setArguments(bundle1);

        pagerAdapter.addFragment(inviteRecommandToAnswerFragment, getString(R.string.inviteRecommand));
        pagerAdapter.addFragment(inviteFriendToAnswerFragment, getString(R.string.inviteFriend));
        vpInviteToAnswer.setOffscreenPageLimit(2);
        vpInviteToAnswer.setAdapter(pagerAdapter);
        vpInviteToAnswer.setCurrentItem(0);
        tab_layout.setViewPager(vpInviteToAnswer);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.ibBack:
                finish();
                break;
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkHttpUtils.getInstance().cancelTag(TAG);
    }

}
